package com.leetcode.LC;

import java.util.ArrayList;
import java.util.HashMap;

public class LC914 {

    public boolean hasGroupsSizeX(int[] deck) {
        if (deck.length == 1) {
            return false;
        }
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i : deck) {
            if (map.containsKey(i)) {
                map.put(i, map.get(i) + 1);
            } else {
                map.put(i, 1);
            }
        }

        ArrayList<Integer> list = new ArrayList<>();

        for (Integer value : map.values()) {
            list.add(value);
        }
        int min = list.get(0);
        for (int i = 1; i < list.size(); i++) {
            min=gcd(list.get(i),min);
        }
        return min>1;
    }
    public int gcd(int a, int b)
    {
        if (a == b)
            return a;
        return gcd(Math.min(a, b), Math.abs(a - b));
    }

    public static void main(String[] args) {
        System.out.println(new LC914().hasGroupsSizeX(new int[]{1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3}));
    }
}
